import RouteComponent from './components';
import { Redirect } from 'react-router-dom';

const routes = [
  {
    path: '/login',
    meta: { title: '登录' },
    component: RouteComponent.Login
  },
  {
    render(props) {
      const token = localStorage.getItem('wl-token-key');
      const { location, route } = props;
      console.log(location, route)
      if (!token) {
        return <Redirect to='/login' />;
      }
      return <RouteComponent.Layout {...props} />;
    },
    routes: [
      {
        path: '/',
        exact: true,
        meta: { title: '首页' },
        render: () => <Redirect to='/home' />
      },
      {
        path: '/home',
        name: 'home',
        meta: { title: '首页' },
        component: RouteComponent.Home
      },
    ]
  }
];

export default routes;